package de.bloxel.world;

import java.util.HashMap;
import java.util.Map;

import com.jme3.math.Vector3f;

import de.bloxel.core.Bloxel;

public class BloxelCache {

  Map<Vector3f, Bloxel> cache = new HashMap<Vector3f, Bloxel>();

  public Bloxel getFromCache(final Vector3f position) {
    return cache.get(position);
  }

  public int getSize() {
    return cache.size();
  }

  public boolean putInCache(final Bloxel bloxel) {
    if (!cache.containsKey(bloxel.getLocalTranslation())) {
      cache.put(bloxel.getLocalTranslation().clone(), bloxel);
      return true;
    }
    return false;
  }

  public boolean remove(final Vector3f targetPosition) {
    return cache.remove(targetPosition) != null;
  }
}
